<?php

namespace App\Http\Controllers;

use App\Services\BuildingService;
use App\Tools\JsonTools;
use Illuminate\Http\Request;

class BuildingController extends Controller
{
    /**
     * @Notes:获取楼市圈信息
     * @Author:Planb,
     * @Date: 2022/11/18,
     * @Time: 19:15,
     */
    public function getBuildInfo(Request $request)
    {
        $uid = $request->id;

        $buildInfoResult = BuildingService::getBuildingInfo($uid);
        if ($buildInfoResult) {
            return JsonTools::JsonSuccess($buildInfoResult, 200, 'ok');
        } else {
            return JsonTools::JsonError([], 6001, '无数据');
        }

    }

    /**
     * @Notes:删除楼市圈信息
     * @Author:Planb,
     * @Date: 2022/11/18,
     * @Time: 19:15,
     */
    public function deleteInfo(Request $request)
    {
        $uid = $request->id;
        $buildInfoId = $request->get('build_id');
        $deleteResult = BuildingService::deleteBuildInfo($uid, $buildInfoId);

        if ($deleteResult) {
            return JsonTools::JsonSuccess($deleteResult, 200, '删除成功');
        } else {
            return JsonTools::JsonError([], 5001, '删除失败');
        }
    }

    /**
     * @Notes:发布楼市圈信息
     * @Author:Planb,
     * @Date: 2022/11/19,
     * @Time: 8:05,
     */
    public static function pushBuild(Request $request)
    {
        $uid = $request->id;
        $message = $request->post('message');
        $image = $request->post('image');
        if (empty($message)) {
            return JsonTools::JsonError([], '7001', '内容为空');
        }
        if (empty($image)) {
            return JsonTools::JsonError([], '7001', '图片为空');
        }
        $pushResult = BuildingService::pushBuildInfo($uid, $message, $image);
        if ($pushResult) {
            return JsonTools::JsonSuccess($pushResult, 200, '发布成功');
        } else {
            return JsonTools::JsonError([], 5001, '发布失败');
        }
    }


    /**
     * @Notes:客户端获取楼市圈信息
     * @Author:Planb,
     * @Date: 2022/11/29,
     * @Time: 14:58,
     */
    public function clientGetBuildInfo()
    {
        $result = BuildingService::clientGetBuildInfo();
        if ($result) {
            return JsonTools::JsonSuccess($result, 200, 'ok');
        } else {
            return JsonTools::JsonError([], 5001, '无楼市圈信息');
        }
    }
}
